home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / program / t_bcinfo.zip / TI714.ZIP / TI714.ASC
Text File  |  1992-02-25  |  4KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  714
  9.   VERSION  :  2.0
  10.        OS  :  DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/3
  12.  
  13.     TITLE  :  Trapping Disk Errors
  14.  
  15.  
  16.  
  17.  
  18.   /*******************************************************
  19.   This program will trap disk errors and prompt the user for
  20.   action. Try running it with no disk in drive A: to invoke
  21.   its functions.
  22.   ********************************************************/
  23.  
  24.   #include <stdio.h>
  25.   #include <conio.h>
  26.   #include <dos.h>
  27.  
  28.   #define IGNORE       0
  29.   #define RETRY        1
  30.   #define ABORT        2
  31.  
  32.   int buf[500];
  33.  
  34.    /* define the error messages for trapping
  35.       disk problems */
  36.   static char *err_msg[] = {
  37.        "write protect",
  38.        "unknown unit",
  39.        "drive not ready",
  40.        "unknown command",
  41.        "data error (CRC)",
  42.        "bad request",
  43.        "seek error",
  44.        "unknown media type",
  45.        "sector not found",
  46.        "printer out of paper",
  47.        "write fault",
  48.        "read fault",
  49.        "general failure",
  50.        "reserved",
  51.        "reserved",
  52.        "invalid disk change"
  53.    };
  54.   /*
  55.      User error interface
  56.   */
  57.   error_win(char *msg)
  58.   {
  59.       int retval;
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                            NUMBER  :  714
  75.   VERSION  :  2.0
  76.        OS  :  DOS
  77.      DATE  :  February 25, 1992                        PAGE  :  2/3
  78.  
  79.     TITLE  :  Trapping Disk Errors
  80.  
  81.  
  82.  
  83.  
  84.       cputs(msg);
  85.  
  86.    /* prompt for user to press a key to abort,
  87.       retry, ignore */
  88.       while(1)
  89.       {
  90.           retval= getch();
  91.           if (retval == 'a' || retval == 'A')
  92.           {
  93.               retval = ABORT;
  94.               break;
  95.           }
  96.           if (retval == 'r' || retval == 'R')
  97.           {
  98.               retval = RETRY;
  99.               break;
  100.           }
  101.           if (retval == 'i' || retval == 'I')
  102.           {
  103.               retval = IGNORE;
  104.               break;
  105.           }
  106.       }
  107.  
  108.       return(retval);
  109.    }
  110.  
  111.    /* pragma warn -par reduces warnings which
  112.       occur due to the non use of the
  113.       parameters errval, bp and si to the
  114.       handler */
  115.    #pragma warn -par
  116.  
  117.   int handler(int errval,int ax,int bp,int si)
  118.   {
  119.       static char msg[80];
  120.       unsigned di;
  121.       int drive;
  122.       int errorno;
  123.  
  124.       di= _DI;
  125.    /* if this is not a disk error then it was
  126.       another device having trouble */
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                            NUMBER  :  714
  141.   VERSION  :  2.0
  142.        OS  :  DOS
  143.      DATE  :  February 25, 1992                        PAGE  :  3/3
  144.  
  145.     TITLE  :  Trapping Disk Errors
  146.  
  147.  
  148.  
  149.  
  150.       if (ax < 0)
  151.       {
  152.       /* report the error */
  153.          error_win("Device error");
  154.       /* and return to the program directly
  155.          requesting abort */
  156.          hardretn(ABORT);
  157.       }
  158.    /* otherwise it was a disk error */
  159.       drive = ax & 0x00FF;
  160.       errorno = di & 0x00FF;
  161.    /* report which error it was */
  162.       sprintf(msg, "Error: %s on drive "
  163.           "%c\r\nA)bort, R)etry, I)gnore: ",
  164.            err_msg[errorno], 'A' + drive);
  165.    /* return to the program via dos interrupt
  166.       0x23 with abort, retry or ignore
  167.       as input by the user */
  168.       hardresume(error_win(msg));
  169.       return ABORT;
  170.   }
  171.   #pragma warn +par
  172.  
  173.  
  174.   main()
  175.   {
  176.    /* install our handler on the hardware
  177.       problem interrupt */
  178.       harderr(handler);
  179.       clrscr();
  180.       printf("Make sure there is no disk in "
  181.               "drive A:\n");
  182.       printf("Press any key ....\n");
  183.       getch();
  184.       printf("Trying to access drive A:\n");
  185.       printf("fopen returned %p\n",
  186.              fopen("A:temp.dat", "w"));
  187.       return 0;
  188.   }
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.